package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBcon {
	private static final String DRIVER_CLASS="com.mysql.jdbc.Driver";
	private static final String url="jdbc:mysql://localhost:3306/login?useUnicode=true&characterEncoding=UTF-8";
	private static final String user="root";
	private static final String pwd="ywj123";
	public static Connection getConnection() {
		Connection dbConnection=null;
		try {
			Class.forName(DRIVER_CLASS);
			dbConnection=DriverManager.getConnection(url,user,pwd);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return dbConnection;
		
	}
	public static void closeConnection(Connection dbConnection) {
		try {
			if(dbConnection!=null&&(!dbConnection.isClosed())) {
				dbConnection.close();
			}
		}catch(SQLException sqlEX) {
			sqlEX.printStackTrace();
		}
	}
	public static void closeResult(ResultSet res) {
		try {
			if(res!=null) {
				res.close();
				res=null;
			}
		}catch(SQLException sqlEX) {
			sqlEX.printStackTrace();
	}

}
	public static void closeStatement(PreparedStatement pStatement) {
		try {
			if(pStatement!=null) {
				pStatement.close();
				pStatement=null;
			}
			
		}catch(SQLException sqlEX) {
			sqlEX.printStackTrace();
		}
	}
}